//
//  JKEmojiKeyboardCell.swift
//  表情键盘
//
//  Created by albert on 16/6/26.
//  Copyright © 2016年 albert. All rights reserved.
//  自定义cell

import UIKit

class JKEmojiKeyboardCell: UICollectionViewCell {
    
    /** 表情 */
    var emojiIcon: JKEmojiModel? {
        didSet {
            // 1.显示emoji表情
            iconButton.setTitle(emojiIcon?.emoticonStr ?? "", forState: UIControlState.Normal)
            
            // 2.设置图片表情
            iconButton.setImage(nil, forState: UIControlState.Normal)
            iconButton.setImage(nil, forState: UIControlState.Highlighted)
            if emojiIcon?.chs != nil {
                iconButton.setImage(UIImage(contentsOfFile: emojiIcon!.pngPath!), forState: UIControlState.Normal)
            }
            
            // 3.设置删除按钮
            if emojiIcon!.isDeleteButton {
                iconButton.setImage(UIImage(named: "compose_emotion_delete"), forState: UIControlState.Normal)
                iconButton.setImage(UIImage(named: "compose_emotion_delete_highlighted"), forState: UIControlState.Highlighted)
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        setupUI()
    }
    
    /** 初始化 */
    private func setupUI() {
        
        // 1.添加子控件
        addSubview(iconButton)
        
        // 2.布局子控件
        iconButton.frame = CGRectInset(bounds, 5, 5)
    }
    
    /** 表情按钮 */
    private lazy var iconButton: UIButton = {
        let btn = UIButton()
        // 设置emoji表情的大小
        btn.titleLabel?.font = UIFont.systemFontOfSize(30)
        btn.userInteractionEnabled = false
        
        return btn
    }()
}
